package com.qtong.controller.assignment;

import com.qtong.entity.Result;
import com.qtong.entity.cinemas.Cinemas;
import com.qtong.entity.movies.Movie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;

/**
 * Assignment helper endpoints: provide query endpoints required by the assignment and a simple purchase flow.
 * This controller is intentionally minimal and designed for demonstration and grading purposes.
 */
@RestController
@RequestMapping("/assignment")
public class AssignmentController {

    @Autowired
    private com.qtong.service.AssignmentService assignmentService;

    /**
     * a) 查找某城市下的影院信息，例如 ?city=济南
     */
    @GetMapping("/cinemas")
    public Result cinemasByCity(@RequestParam String city) {
        List<Cinemas> list = assignmentService.findCinemasByCity(city);
        return Result.success(list);
    }

    /**
     * b) 查找某影院正在上映的影片（简单定义：场次 showTime 在未来）
     */
    @GetMapping("/cinemas/{cinemaId}/now-playing")
    public Result moviesNowPlaying(@PathVariable String cinemaId) {
        List<Movie> movies = assignmentService.findMoviesNowPlaying(cinemaId);
        return Result.success(movies);
    }

    /**
     * c) 根据经纬度查找最近的影院（需要 cinemas collection 有 location 类型为 GeoJSON point）
     */
    @GetMapping("/cinemas/nearby")
    public Result nearby(@RequestParam double lng, @RequestParam double lat, @RequestParam(defaultValue = "2") int limit) {
        List<Cinemas> list = assignmentService.findNearby(lng, lat, limit);
        return Result.success(list);
    }

    /**
     * d) 按导演查找影片
     */
    @GetMapping("/movies/by-director")
    public Result moviesByDirector(@RequestParam String director) {
        List<Movie> list = assignmentService.findMoviesByDirector(director);
        return Result.success(list);
    }

    /**
     * e) 按演员查找影片
     */
    @GetMapping("/movies/by-actor")
    public Result moviesByActor(@RequestParam String actor) {
        List<Movie> list = assignmentService.findMoviesByActor(actor);
        return Result.success(list);
    }

}
